livecodefandomcom-20200223-history
Do
Executes a list of statements. Syntax: do statementList do statementList in do statementList as alternateLanguageName Examples: do "go next card" do "put " & x & " into tNumberOfRecords" x -- might become "put 3 into tNumberOfRecords" do "select" & line 3 of field "Objects" do field "Statements" as AppleScript do "myfunction(myparam1,myparam2);" in browser Use the do command to execute statements in a container, or to execute a statement that consists partly of a literal string and partly of a container or the return value from a function. Parameters: *statementList - A LiveCode statement, a container with one or more statements, or a string that evaluates to a statement. *alternateLanguageName - **On Mac OS and OS X systems, the alternateLanguageName is a script language (such as AppleScript) supported under the Open Scripting Architecture. **On Windows systems, the alternateLanguageName is an "active scripting" language (such as VBScript) supported by the Windows Scripting Host. The available languages are returned by the alternateLanguages function. If you specify an alternateLanguageName, the statementList must be written in the specified language. **In HTML5 applications, "JavaScript" is the only supported alternateLanguage. The result is set to the value returned by executing the statementList, as long as the value is a scalar (a string, number, boolean or undefined). Returning JavaScript arrays or objects is not supported. *caller - Has the effect of executing the statementList in the context of the handler. Using the do command is slower than directly executing the commands, because each statement must be compiled every time the do command is executed. On Mac OS X systems, if you use the do as alternateLanguageName form, any result returned by the script language is placed in the result. On Windows systems, the result function will return the value of the global variable called "result" in the script that was executed (or empty if no such variable was defined). For example the following code will produce a dialog box containing "2": do "result = 1 + 1" as "vbscript" answer the result Important! If using the do as alternateLanguageName form, any paths used in the statementList must be in the native format of the current system. In particular this means that paths must be converted to Windows native format before use on Windows machines. In most cases this can be done by replacing slash with backslash in the path. If you attempt to specify an alternateLanguageName on a Unix system, the do command is not executed, and the result is set to "alternate language not found". Any scripts on Windows which contain references to WScript will fail to run as WScript objects do not exist in the LiveCode Environment. Return values should therefore be placed within the global result variable instead of using WScript.Echo. To see how to create a numbered set of variables see the dictionary entry for the local command. Note To call a javascript in a browser use: do "myfunction(myparam1,myparam2);" in browser #result from javascript will be in result if the result = true then beep Here's an example javascript. Note you can return value < html> < head> < script type="text/javascript"> function helloWorld(hello1){ alert(hello1); return true; } < body> See Also alternateLanguages function, call command, debugDo command, local command, breakpoint command, message box keyword Category:Commands Category:HTML5